package ui.topic;

import entity.domain.value.DiscreteValue;

import javax.swing.*;
import javax.swing.plaf.metal.OceanTheme;
import java.awt.*;
import java.awt.event.*;

public class DiscreteTopicPanel extends TopicPanel {

    private JComboBox cb_options;

    public DiscreteTopicPanel(String name, double topicWeight,Object[] options, UpdateBidInfo updateBidInfo){
        super(name, topicWeight);
        cb_options = new JComboBox();
        //cb_options.setPreferredSize(new Dimension(80, 32));
        cb_options.setBackground(Color.white);
        cb_options.setForeground(Color.gray);
        for(Object option: options){
            cb_options.addItem(option);
        }
        this.value = new DiscreteValue(cb_options.getSelectedIndex(), cb_options.getSelectedItem().toString().split("\\(" )[0]);
        this.add(cb_options);
        //this.setSize(80, 50);
        cb_options.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ((DiscreteValue)value).setNum(cb_options.getSelectedIndex());
                ((DiscreteValue)value).setValue(cb_options.getSelectedItem().toString().split("\\(")[0]);
                updateBidInfo.updateBidInfo();
                //System.out.println(value);
            }
        });
    }

    public int getOptionNum(){
        return ((DiscreteValue)value).getNum();
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        //frame.setContentPane(new DiscreteTopicPanel("A", 0.25,new Object[]{"a1", "a2", "a3"}));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
